package ru.pb.game.network.engine.client.packets.receivable;

import ru.pb.game.network.engine.client.packets.FromClientToGameServerPacket;
import ru.pb.game.network.engine.client.packets.sendable.PROTOCOL_ROOM_CHANGE_TEAM_ACK;
import ru.pb.game.objects.model.players.Player;

public class PROTOCOL_ROOM_CHANGE_TEAM_REQ extends FromClientToGameServerPacket
{
	private int _team = -1;
	private int _oldSlot;

	@Override
	public void readImpl()
	{
		readH();
		if(_buf.remaining() > 0)
			_team = readD();
	}

	@Override
	public void runImpl()
	{
		Player p = getPlayer();
		if(p != null)
		{
			if(_team >= 0)
			{
				_oldSlot = p.getSlot();
				p.getRoom().setNewSlot(p, _team);
				p.sendPacket(new PROTOCOL_ROOM_CHANGE_TEAM_ACK(_oldSlot, p));
			}
		}
	}
}